/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../data_struct/pool.h"
#include "../msg/head.h"
#include "include.h"
#include "hook.h"

namespace xos_box
{

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    hook::hook()
    {
    }

    hook::~hook()
    {
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    int hook::init()
    {
        int ret = 0;

        if( 0 == ret )
        {
            ret = pool::init();
        }

        // test
        if( 0 == ret )
        {
            ret = all_done_test::init_all();
        }

        // string
        if( 0 == ret )
        {
            ret = wstring_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = string_impl::init_all();
        }

        // buf
        if( 0 == ret )
        {
            ret = big_buf_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = buf_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = msg_impl::init_all();
        }

        // lock num, obj
        if( 0 == ret )
        {
            ret = lock_num::init_all();
        }

        if( 0 == ret )
        {
            ret = lock_obj::init_all();
        }

        // heart time
        if( 0 == ret )
        {
            ret = heart_impl::init_all();
        }

        // callback & engine
        if( 0 == ret )
        {
            ret = lock_free_queue_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = callback_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = threads_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = engine_impl::init_all();
        }

        // list
        if( 0 == ret )
        {
            ret = list_impl::init_all();
        }

        // 复杂类型
        if( 0 == ret )
        {
            ret = serial_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = variant_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = str_property_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = int_property_impl::init_all();
        }

        return ret;
    }

    int hook::term()
    {
        int ret = 0;

        // 复杂类型放前边
        int_property_impl::term_all();
        str_property_impl::term_all();
        variant_impl::term_all();
        serial_impl::term_all();

        // 
        // i_release obj list should release first
        // 
        list_impl::term_all();

        // 
        // callback & engine
        // 
        engine_impl::term_all();
        threads_impl::term_all();
        callback_impl::term_all();
        lock_free_queue_impl::term_all();

        // 
        // time
        //
        heart_impl::term_all();

        // lock obj
        lock_obj::term_all();
        lock_num::term_all();

        // 
        // buf
        // 
        big_buf_impl::term_all();
        buf_impl::term_all();
        msg_impl::term_all();

        // string
        string_impl::term_all();
        wstring_impl::term_all();

        // test
        all_done_test::term_all();

        // pool
        pool::term();

        return ret;
    }

} // xos_box
